﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Query2Object;

/// <summary>
///EmployeeMoudle 的摘要说明
/// </summary>
public class EmployeeMoudle
{
    public static List<SqlDb.Employees> GetEmployees()
    {
        using (ISession session = dbContext.Current().GetContext("SqlDb").GetSession())
        {
            SqlDb.Employees emp = new SqlDb.Employees();
            IQuery query = session.GetQuery(emp).OrderBy(SqlDb.Employees.BIRTHDATE, Direction.DESC);
            return query.GetList<SqlDb.Employees>();

            query.SetUpdateProperty(SqlDb.Employees.BIRTHDATE);
            query.Update();
        }
    }
    public static void UpdateEmployee(SqlDb.Employees param)
    {
        using (ISession session = dbContext.Current().GetContext("SqlDb").GetSession())
        {
            Exp exp;
            
            session.Update(param);
        }
    }

    public static DataTable GetCountByPrice()
    {
        using (ISession session = dbContext.Current().GetContext("SqlDb").GetSession())
        {
            SqlDb.Products pd = new SqlDb.Products();
            IQuery q = session.GetQuery(pd).OrderBy(SqlDb.Products.PRODUCTNAME, Direction.DESC);
            q.Sum(SqlDb.Products.UNITPRICE);
            q.Avg(SqlDb.Products.UNITPRICE);
            q.max(SqlDb.Products.UNITPRICE);
            q.min(SqlDb.Products.UNITPRICE);
            q.GroupBy(SqlDb.Products.PRODUCTNAME);
            q.OrderBy(SqlDb.Products.CATEGORYID,Direction.DESC);
            return q.GetStatistics();
        }
    }

    public static DataSet GetEmployeeByAdo()
    {
        using (SqlConnection conn = new SqlConnection(@"Data Source=localhost\PERSON2000;Initial Catalog=Northwind;Persist Security Info=True;User ID=sa;Password=123"))
        {
            SqlCommand cmd = new SqlCommand("SELECT * FROM [Employees] Order by [BirthDate] desc", conn);
            conn.Open();
            SqlDataAdapter adt = new SqlDataAdapter(cmd);
            DataSet rs = new DataSet();
            adt.Fill(rs);
            conn.Close();
            return rs;
        }
    }
}
